<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>验证码下载</title>

    <!--    屏幕自适应-->
    <script name="viewport" content="width=device-width, initial-scale=1"></script>
    <!--    引入bootstrap-->
    <link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.min.css">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <!-- style CSS -->
    <link rel="stylesheet" href="css/style.css" type="text/css" media="all">
    <!-- google fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;700&display=swap" rel="stylesheet">

    <!--    bootstrap依赖jQuery-->
    <script src="js/jquery.min.js"></script>
    <script src="bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
    <script src="js/http.js"></script>

</head>
<body>
<div>

    <section class = "main" >
        <div class = "logo text-center" >
            <h1 ><a href = "login.html" > 暴富云盘</a ></h1 >
        </div >
        <div class = "text-center" style="background-color: gainsboro;width: 400px;height: 300px">

            <form>
            <div style="background-color:dodgerblue;font-size: 30px;height: 80px;padding: 15px">
                <img src = "img/admin.png" >提取私密文件

            </div>
            <div>&nbsp;</div>
                <div>&nbsp;</div>
            <div class = "wthree-field" >
                    <label >
                        <input type="text" placeholder="请输入提取码" name="code" >
                    </label >
            </div >
                <div>&nbsp;</div>

        <div>
            <input class = "btn " type = "reset" value = "重置" >
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input class = "btn bg-primary " onclick = "checkCode()" type = "button" value = "确认" >

        </div>
            </form>
        </div >

        <div class = "copyright" >
            <p >©使用暴富网盘你每天都幸福 <a
                    href = "http://www.chinacharityfederation.org/" target = "_blank" >加油把骚年</a ></p >
        </div >
    </section >

<!--    <input type="text" placeholder="请输入提取码" name="code" >-->
<!--    <a class="btn btn-default btn-danger btn-lg" role="button" onclick="checkCode()">确认</a></p>-->
</div>
</body>
</html>
<script>

    let url = window.location.href;

    console.log(url)
    $(document).ready(function() {
        $.ajax({
            type: "post",
            url: "http://localhost:8080/netdisc/document/document/checkDocument",
            data: {
                url: url
            },
            success: function (resp) {
                let parse = JSON.parse(resp);
                if(parse.data!="有验证码"){
                    location.href=parse.data
                }
            }
        })
    })

    function checkCode() {
        let code = $("[name='code']").val();
        $.ajax({
            type:"post",
            url:"http://localhost:8080/netdisc/document/document/checkCode",
            data:{
                url:url,
                code:code,
            },
            success:function (resp) {
                //let parse = JSON.parse(resp);
                let message = resp.message;
                console.log(resp)
                if(resp.data!=""){

                    location.href=resp.data

                }else{
                    alert(message);
                    location.reload();
                }
            }
        })
    }
</script>